/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.board;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.board.BoardType;

/**
 * @author Alucard (email:357375084@qq.com)
 * @since 2013-03-14
 */
@Service("boardtypeService")
public class boardtypeServiceImpl implements boardtypeService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of boardtype
     ****************************************/
    public void insert(BoardType boardtype) throws Exception {
        boardtype.setTypeid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(boardtype);
    }

    /****************************************
     * Update a instace of boardtype
     ****************************************/
    public void update(BoardType boardtype) throws Exception {
        iDataSet4iBatis.update(boardtype);
    }

    /****************************************
     * Delete a instace of boardtype
     ****************************************/
    public void delete(BoardType boardtype) throws Exception {
        iDataSet4iBatis.delete(boardtype);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(BoardType boardtype) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(BoardType boardtype) throws Exception {
        String statementId = boardtype.getStatmentId();
        String mainId = boardtype.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> boardtypeList = new ArrayList<BaseModel>();
        for (String id : ids) {
            BoardType model = new BoardType();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            boardtypeList.add(model);
        }
        iDataSet4iBatis.batchDelete(boardtypeList);
    }

    /****************************************
     * Query instaces of boardtype
     ****************************************/
    public List<BaseModel> queryAsList(BoardType boardtype) throws Exception {
        String queryListStatement = "";
        if (boardtype.isPaging()) {
            queryListStatement = boardtype.getStatmentId();
            boardtype.setStatmentId("BoardType.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(boardtype);
            boardtype.setTotalCount(baseModel.getTotalCount());
            boardtype.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(boardtype);
    }

    /****************************************
     * Query a instaces of boardtype
     ****************************************/
    public BaseModel queryAsObject(BoardType boardtype) throws Exception {
        return iDataSet4iBatis.queryAsObject(boardtype);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
